import React from 'react';
import { Navigate } from 'react-router-dom';
import { isLoggedIn } from '../utils/auth';

interface AuthGuardProps {
  children: React.ReactNode;
}

const AuthGuard: React.FC<AuthGuardProps> = ({ children }) => {
  if (!isLoggedIn()) {
    // 用户未登录，重定向到登录页面
    return <Navigate to="/login" replace />;
  }

  // 用户已登录，渲染子组件
  return <>{children}</>;
};

export default AuthGuard;